/*
 * init.cpp
 *
 *  Created on: 20.12.2010
 *      Author: Dmitry Bratus
 */

#include "init.hpp"
#include "rbatch_parser.hpp"
#include "rstml_exception.hpp"
#include <stml_exception.hpp>

using namespace stml;

void Init_rstml() {
    VALUE mSTML = rb_define_module("STML");

    rb_define_const(mSTML, "ERR_UNSUPPORTED_GENERATOR_TYPE", INT2FIX((int)StmlException::UNSUPPORTED_GENERATOR_TYPE));
    rb_define_const(mSTML, "ERR_INTERNAL_TO_OUTPUT_CONVERSION_NOT_SUPPORTED", INT2FIX((int)StmlException::INTERNAL_TO_OUTPUT_CONVERSION_NOT_SUPPORTED));
    rb_define_const(mSTML, "ERR_INPUT_TO_INTERNAL_CONVERSION_NOT_SUPPORTED", INT2FIX((int)StmlException::INPUT_TO_INTERNAL_CONVERSION_NOT_SUPPORTED));
    rb_define_const(mSTML, "ERR_CHARACTER_CANNOT_BE_CONVERTED_TO_OUTPUT_FORMAT", INT2FIX((int)StmlException::CHARACTER_CANNOT_BE_CONVERTED_TO_OUTPUT_FORMAT));
    rb_define_const(mSTML, "ERR_UNKNOWN_TAG", INT2FIX((int)StmlException::UNKNOWN_TAG));
    rb_define_const(mSTML, "ERR_NAMELESS_INLINE_TAG", INT2FIX((int)StmlException::NAMELESS_INLINE_TAG));
    rb_define_const(mSTML, "ERR_UNKNOWN_ALIGNMENT", INT2FIX((int)StmlException::UNKNOWN_ALIGNMENT));
    rb_define_const(mSTML, "ERR_UNEXPECTED_CLOSE_TAG", INT2FIX((int)StmlException::UNEXPECTED_CLOSE_TAG));
    rb_define_const(mSTML, "ERR_INLINE_TAG_ALREADY_EXISTS", INT2FIX((int)StmlException::INLINE_TAG_ALREADY_EXISTS));
    rb_define_const(mSTML, "ERR_UNSUPPORTED_HEADER_LEVEL", INT2FIX((int)StmlException::UNSUPPORTED_HEADER_LEVEL));

    VALUE cStmlException = rb_define_class_under(mSTML, "StmlException", rb_eException);
    rb_define_method(cStmlException, "initialize", RUBY_METHOD_FUNC(rstml_exception_initialize), 3);
    rb_define_method(cStmlException, "error_code", RUBY_METHOD_FUNC(rstml_exception_error_code), 0);
    rb_define_method(cStmlException, "line_no", RUBY_METHOD_FUNC(rstml_exception_line_no), 0);
    set_rstml_exception_class(cStmlException);

    VALUE cParser = rb_define_class_under(mSTML, "BatchParser", rb_cObject);
    rb_define_singleton_method(cParser, "new", RUBY_METHOD_FUNC(rbatch_parser_class_new), 0);
    rb_define_method(cParser, "initialize", RUBY_METHOD_FUNC(rbatch_parser_initialize), 0);
    rb_define_method(cParser, "<<", RUBY_METHOD_FUNC(rbatch_parser_append_stml), 1);
    rb_define_method(cParser, "generate", RUBY_METHOD_FUNC(rbatch_parser_generate), 1);
}
